package pro.spring.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import pro.spring.inter.MessagesMapper;
import pro.spring.model.Messages;
import pro.spring.vo.PaginationVo;

@Service
public class MessagesService{

	@Autowired
	private MessagesMapper MessagesMapper;
	
	public int deleteByPrimaryKey(Integer id) {
		return MessagesMapper.deleteByPrimaryKey(id);
	}

	public int insert(Messages record) {
		return MessagesMapper.insert(record);
	}

	public Messages selectByPrimaryKey(Integer id) {
		return MessagesMapper.selectByPrimaryKey(id);
	}

	public int updateByPrimaryKey(Messages record) {
		return MessagesMapper.updateByPrimaryKey(record);
	}
	public int messagePageNum(int inId){
		int allPageNum=1;
		int allNum=MessagesMapper.selectCountByInid(inId);
		if(allNum%5==0&&allNum>=5){
			allPageNum=allNum/5;
		}else if(allNum<5){
			allPageNum=1;
		}else{
			allPageNum=allNum/5+1;
		}
		return allPageNum;
	}
	
	public PaginationVo<Messages> getPaginationInfo(int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Messages> pageVo=new PaginationVo<Messages>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(MessagesMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(MessagesMapper.selectListPage(pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
	
	public PaginationVo<Messages> getPaginationInfoByInid(int inId,int pagenum,int pagesize){
		//int pagenum是当前的页码,int pagesize是每页显示的数据数量
		PaginationVo<Messages> pageVo=new PaginationVo<Messages>();
		//一定要在setPageCount()方法之后执行setPageNum
		pageVo.setCount(MessagesMapper.selectCount());
		pageVo.setRows(pagesize);
		pageVo.setPageNum(pagenum);
		pageVo.setList(MessagesMapper.selectByInid(inId,pageVo.getOffset(), pageVo.getRows()));
		return pageVo;
	}
}
